package cms_article

import (
	category "gitee.com/binny_w/gin_starter/model/cms_category"
	util2 "gitee.com/binny_w/go-util/v2"
	"github.com/gin-gonic/gin"
)

func ListFixer(c *gin.Context, row *util2.MysqlRow) error {
	row.Set("category", "-")
	if tree, err := category.Tree(c); err == nil {
		if item, ok := tree.ItemByKey(row.ToStr("category_key")); ok {
			ret := ""
			for _, i := range tree.Ancestors(item.Key) {
				ret += i.Label + " / "
			}
			ret += item.Label
			row.Set("category", ret)
		}
	}
	row.Drop("content", "cover", "tags", "category_key")
	return nil
}
